package cn.edu.nju.software.cdiy.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import cn.edu.nju.software.cdiy.bean.Hcomment;
import cn.edu.nju.software.cdiy.bean.Value;
import cn.edu.nju.software.cdiy.dao.HcommentDao;
import cn.edu.nju.software.cdiy.dao.ValueDao;
import cn.edu.nju.software.cdiy.service.HcommentService;

public class HcommentServiceImpl implements HcommentService {
 
	@Autowired
	private HcommentDao hcommentDao;
	@Autowired
	private ValueDao valueDao;

	public void setHcommentDao(HcommentDao hcommentDao) {
		this.hcommentDao = hcommentDao;
	}

	public void setValueDao(ValueDao valueDao) {
		this.valueDao = valueDao;
	}

	@Override
	public List<Hcomment> getUserComments(Long userid) {
		return this.hcommentDao.getUserComments(userid);
	}

	@Override
	public Hcomment saveHComment(Hcomment comment) {
		comment.setTime(new Date(System.currentTimeMillis()));
	    Value v = valueDao.getValue(comment.getHardwareType().getValue());
	    comment.setHardwareType(v);
		return this.hcommentDao.saveHcomment(comment);
	}

	@Override
	public void deleteHComment(Hcomment comment) {
		this.hcommentDao.deleteHComment(comment);
	}

	@Override
	public void deleteHCommentByID(Long hcommentid) {
		this.hcommentDao.deleteHCommentByID(hcommentid);
	}

	@Override
	public List<Hcomment> getUserHCommentPage(int hardwareid, String hardwareType, int page) {
		return this.hcommentDao.getUserHCommentPage(hardwareid, valueDao.getValue(hardwareType), page);
	}

	@Override
	public int getUserHCommentLength(int hardwareid, String hardwareType) {
		return this.hcommentDao.getUserHCommentLength(hardwareid, valueDao.getValue(hardwareType));
	}

	@Override
	public List<Hcomment> getExpertHCommentPage(int hardwareid, String hardwareType, int page) {
		return this.hcommentDao.getExpertHCommentPage(hardwareid, valueDao.getValue(hardwareType), page);
	}

	@Override
	public int getExpertHCommentLength(int hardwareid, String hardwareType) {
		return this.hcommentDao.getExpertHCommentLength(hardwareid, valueDao.getValue(hardwareType));
	}

	@Override
	public List<Integer> getExpertNumberList(int hardwareid,
			String hardwareType) {
		return this.hcommentDao.getExpertNumberList(hardwareid, valueDao.getValue(hardwareType));
	}

	@Override
	public List<Integer> getUserNumberList(int hardwareid, String hardwareType) {
		return this.hcommentDao.getUserNumberList(hardwareid, valueDao.getValue(hardwareType));
	}

	@Override
	public Hcomment getNewUserHComment(int hardwareid, String hardwareType) {
		return this.hcommentDao.getNewUserHComment(hardwareid, valueDao.getValue(hardwareType));
	}

	@Override
	public Hcomment getNewExpertHComment(int hardwareid, String hardwareType) {
		return this.hcommentDao.getNewExpertHComment(hardwareid, valueDao.getValue(hardwareType));
	}

}
